package dto

import (
	"backEnd/common"
	"backEnd/model"
	"net/http"

	"github.com/gin-gonic/gin"
)

func GetUserById(ctx *gin.Context) {
	reqUser := &model.User{}
	ctx.ShouldBindJSON(&reqUser)
	DB := common.GetDB()
	user := model.User{}
	if err := DB.Where("id = ?", reqUser.ID).First(&user).Error; err != nil {
		ctx.JSON(404, gin.H{"msg": "不存在此用户"})
		return
	}

	user.Password = ""
	ctx.JSON(http.StatusOK, gin.H{
		"user": user,
	})
}

func GetInternalUserById(userid uint) *model.User {
	user := &model.User{}
	DB := common.GetDB()
	DB.Where("id = ?", userid).First(user)
	return user
}
